import urllib
from google.appengine.api import urlfetch

import sys
import httplib
import re
import string

def getEntries( tid):

    url = "http://tennislink.usta.com/Tournaments/Reports/ReportPreview.aspx?reportid=1&organizationid=&startdate=08/21/2009&enddate=08/21/2009&tournamentid="
    url += str(tid)
    print url

    result = urlfetch.fetch(url)
    scraped = result.content

    page = scraped.split("\r\n")

    rstrike = r'(FieldLabelStrikeThrough)'                 # withdrawal

    plines=len(page)
    for i in range(0,plines-1):
      fstrike = re.search( rstrike,page[i] ,re.IGNORECASE)

      if(fstrike):
            print page[i]


def USTANumber(id):
    url  = "http://www.ustanorcal.com/playermatchs.asp?id="+str(id) 
    print url

    result = urlfetch.fetch(url)
    scraped = result.content

    rexp = r">USTA #: <b>([\d]*)</b>"   

    r = re.compile(rexp,re.IGNORECASE )
    usta = r.findall( scraped )
#   print usta[0]

#USTANumber(44933)
print("go")
getEntries("508333111")
